import React from 'react';
import { Redirect } from 'umi';
import LoginLayout from './loginLayout';
import MainLayout from './mainLayout';

export default function (props) {
  // 判断 token 是否存在
  const isLogin = window.sessionStorage.getItem('user');
  const { pathname } = props.location;

  if (!isLogin && pathname !== '/login') {
    return <Redirect to={`/login?timestamp=${new Date().getTime()}`} />;
  }
  if (pathname === '/login') {
    return <LoginLayout>{props.children}</LoginLayout>;
  } else {
    return <MainLayout>{props.children}</MainLayout>;
  }
}
